import request from "@/api";
import { BaseRet, ListRet, ObjectRet } from "../../response";
import { ChatMessage, QueryChatMessage, SendChatInfoRet } from "./model";

class ChatMessageApi {
  /**
   * 根据用户查询消息
   * @param data
   * @returns
   */
  static async queryByUser(data: QueryChatMessage): Promise<ListRet<ChatMessage>> {
    return await request({
      url: `ChatMessage/GetChatMessageListByUserId`,
      method: "post",
      data: data,
    });
  }

  /**
   * 查询未读消息
   * @param data
   * @returns
   */
  static async query(): Promise<ListRet<ChatMessage>> {
    return await request({
      url: "chatMessage/GetChatMessageNoReadList",
      method: "get",
    });
  }

  /**
   * 未读消息标记为已读
   * @param data
   * @returns
   */
  static async updateMsgReaded(msgId: string): Promise<BaseRet> {
    return await request({
      url: `chatMessage/updateMsgReaded/${msgId}`,
      method: "get",
    });
  }

  /**
   * 未读消息标记为已读
   * @param data
   * @returns
   */
  static async sendChatCheck(
    touserId: string,
    msgCount: number
  ): Promise<ObjectRet<SendChatInfoRet>> {
    return await request({
      url: `chatMessage/SendChatCheck/${touserId}/${msgCount}`,
      method: "get",
    });
  }
}

export default ChatMessageApi;
